package org.jeecg.jxc.customer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.jxc.customer.entity.Customer;
import org.jeecg.jxc.customer.mapper.CustomerMapper;
import org.jeecg.jxc.customer.service.CustomerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @PackageName: org.jeecg.jxc.customer.service
 * @ClassName: CustomerService
 * @author: zgq
 * @date: 2022/6/21 19:22
 * @Description: 客户管理业务层
 **/
@Service
public class CustomerServiceImpl implements CustomerService {

    @Resource
    private CustomerMapper customerMapper;

    @Override
    public Page<Customer> pageList(Page page, String customer) {
        IPage<Customer> customerIPage = customerMapper.selectPage(page,customer);
        return (Page)customerIPage;
    }

    @Override
    public Boolean save(Integer customerId, Customer customer) {
        if(customerId==null)
            return customerMapper.insert(customer);
        else {
            return customerMapper.update(customer,customerId);
        }
    }

    @Override
    public Boolean deleteByIds(String ids) {
         String[] idss = ids.split(",");
         List<Integer> idList=new ArrayList<>();
         for(String id:idss){
             idList.add(Integer.valueOf(id));
         }
         return customerMapper.deleteByIds(idList);
    }
}
